package cn.lijiguo.concurrency.part1.uncaughtexception;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * MyUnCaughtExceptionHandler
 * 自定义 UncaughtExceptionHandler
 * @author lijiguo
 * @date 2020/1/7 16:29
 */
public class MyUnCaughtExceptionHandler implements Thread.UncaughtExceptionHandler {

    private String name;

    MyUnCaughtExceptionHandler(String name) {
        this.name = name;
    }

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        Logger logger = Logger.getAnonymousLogger();
        logger.log(Level.WARNING, t.getName() + " 线程异常，终止了", e);
        System.out.println(name + " 捕获了异常，" + t.getName() + " 异常 " + e);
    }
}
